<?php
namespace jy_quanfee;
defined('BY_JYA') or exit('error');
/*
	分红佣金
	
*/
class commission extends \plugin{
	/*
		生成佣金
	*/
	function create($order){
		$isopen=intval($this->setting['isopen']);
		if(!$isopen){
			return;
		}
		$this->order=$order;
		$member=$this->get('member',array('mid'=>$order['mid']),array('mid','is_agent','agent_id','level_id'));
		if($member['level_id']){
			$nowlevel=$this->getcolumn('level',array('id'=>$member['level_id']),'level');
		}else{
			$nowlevel=0;
		}
		$agent_id=$member['agent_id'];
		//自购升级
		if($member['is_agent']){
			$this->update('member',array('myorder_price +='=>$order['price']),array('mid'=>$order['mid']));
			$this->model('member')->update_agent_level($order['mid'],$order['id']);
		}
		//现在支付方式分佣
		if($this->setting['pay_type']){
			$paylog=pdo_get('core_paylog',array('id'=>$order['pay_id']),array('pay_type','di_credit','di_fee','fee'));
			if($paylog['di_fee']>0){
				if(strpos($this->setting['pay_type'],';'.$paylog['di_credit'].';') !== false){
					$this->order['price'] -= $paylog['di_fee'];
				}
				if(strpos($this->setting['pay_type'],';'.$order['paytype'].';') !== false){
					$this->order['price'] -= $paylog['fee']-$paylog['di_fee'];
				}
				//两种支付都不支持
				if(strpos($this->setting['pay_type'],';'.$paylog['di_credit'].';') !== false && strpos($this->setting['pay_type'],';'.$order['paytype'].';') !== false){
					return;
				}
			}elseif(strpos($this->setting['pay_type'],';'.$order['paytype'].';') !== false){
				return;
			}
		}
		if($this->order['price']<=0){
			return;
		}
		$this->commission_order=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$this->order['mid'],
				'ordersn'=>$this->order['ordersn'],
				'order_price'=>$this->order['price'],
				'plugin_name'=>$this->order['plugin_name']?:'',
				'commission_money'=>0,
				'ji_money'=>0,
				'jifen'=>0,
				'createtime'=>TIMESTAMP,
		);		
		//佣金计算方式，是否扣除运费
		if($this->setting['commissionfeetype']==1){
			$this->commission_order['commission_price']=$this->order['price'];
		}elseif($this->setting['commissionfeetype']==3){
			$this->commission_order['commission_price']=$this->order['price'] + $this->order['deductcredit'] + $this->order['deductcredit2'];
		}else{
			$this->commission_order['commission_price']=$this->order['price']-$this->order['dispatchprice'];
		}
		//全网分红
		$allmembers=$this->getall('member',array('is_agent'=>1,'stop'=>0,'uniacid'=>$_SESSION['uniacid']));
		foreach($allmembers as $mv){
			$this->up_redfee($mv);
		}	
        $levelnum=12;
		//当分红层级大于0时，逐次寻找上级推荐人并计算佣金
		for($i=0;$i<$levelnum;$i++){
			if(!$agent_id){
				break;
			}
			$member=$this->get('member',array('mid'=>$agent_id,'uniacid'=>$_SESSION['uniacid']));
			$agent_id=$member['agent_id'];
			$this->create_commission($member,$i+1);
			$ta_agent_id=$this->getcolumn('member',array('mid'=>$member['agent_id']),'agent_id');
			if(($agent_id>0 && $ta_agent_id==$agent_id) || $agent_id==$member['mid']){
				break;
			}
		}
		//生成分红订单
		$indata=$this->commission_order;
		unset($indata['ji_money']);
		unset($indata['maxlevel']);
		unset($indata['isarea']);
		$this->insert('order',$indata);
		if($order['sendtype']==3){
			$status=pdo_getcolumn('jy_weishop_order',array('id'=>$order['id'],'uniacid'=>$_SESSION['uniacid']),'status');
			if($status==3){
				$this->order_complete($order);
			}
		}
		return true;
	}
	/*
		团队收益
	*/
	function create_commission($member,$commission_level=1){
		if($member && $member['is_agent'] && $member['stop']==0){
			//相应会员存在且是分红商且状态正常			
			if(!$member['level_id']){
				//获取默认等级佣金比例
				$level_commissions=$this->plugin_setting('default_level');
				$level_id=0;
				$ji_per=$level_commissions['ji_rate'];
			}else{
				$level=$this->get('level',array('id'=>$member['level_id'],'uniacid'=>$_SESSION['uniacid']));
				$level_commissions=json_decode($level['commissions'],true);
				$level_id=$level['id'];
				$ji_per=$level_commissions['ji_rate'];
			}
			$ji_money=0;
			$order_price=$this->commission_order['commission_price'];
			$remark=array(
				'level_id'=>$level_id,
				'commission_level'=>$commission_level,
				'order_price'=>$order_price,
				'goods_commission'=>array(),
			);
			
			//先检查是否存在商品独立佣金规则，如果存在则对订单相应商品部分金额单独计算佣金
			$total_lastcostprice=0;
			//非按笔计算
			$this->needorder=false;
			if($this->setting['get_buyordernum']!=1){
				foreach($this->order['goods'] as $goods){
					if(!$goods['fee_desc'] && $goods['merchid']){
						model('jy_weishop/order')->setfee_desc($goods['orderid']);
					}
					$total_price=$goods['total_price']?$goods['total_price']:pdo_getcolumn('jy_weishop_order_goods',array('id'=>$goods['id']),'total_price');
					$costprice=pdo_getcolumn('jy_weishop_goods',array('id'=>$goods['goodsid']),'costprice');
					$total_costprice=$goods['total']*$costprice;
					$total_lastcostprice +=$total_costprice;
					$goods_commission=$this->get('goods',array('goods_id'=>$goods['goodsid']));
					if(!$goods_commission['id']){
						$this->needorder=true;
						continue;
					}
					if($goods_commission['ignore']){
						$order_price=$order_price-$goods['total_price'];
						continue;
					}
					//如果商品单独设置佣金，将减少本商品的金额
					$order_price=$order_price-$total_price;
					$goods_commission['commissions']=$goods_commission['commissions']?json_decode($goods_commission['commissions'],true):array();
					foreach($goods_commission['commissions'] as $gc){
						if($gc['level_id']==0){
							$demogoods_ji_per=$gc['ji_rate'];
						}
						if($gc['level_id']!=$level_id){
							continue;
						}else{
							$goods_ji_per=$gc['ji_rate'];
							break;
						}
					}
					$goods_ji_per=$goods_ji_per?:$demogoods_ji_per;
					if(substr($goods_ji_per,-1)=='%'){
						//利润计算
						if($this->setting['commissionfeetype']==2){
							$total_price -=$total_costprice;
							$total_lastcostprice -=$total_costprice;
						}
						$goods_ji_money=($total_price*substr($goods_ji_per,0,-1))/100;
					}else{
						$goods_ji_money=$goods_ji_per*$goods['total'];
					}
					$goods_ji_money -=$this->commission_order['ji_money'];
					$ji_money+=$goods_ji_money;
					$remark['goods_commission'][]=array('ordergoodsid'=>$goods['id'],'goods_id'=>$goods['goodsid'],'total_price'=>$total_price,'total'=>$goods['total'],'commission_per'=>$goods_ji_per,'commission_money'=>$goods_ji_money);
				}
			}
			if($this->needorder && $order_price>0){
				if(substr($ji_per,-1)=='%'){
					//利润计算
					if($this->setting['commissionfeetype']==2){
						$order_price -=$total_lastcostprice;
					}
					$order_ji_money=intval($order_price*$ji_per)/100;
				}else{
					$order_ji_money=$ji_per;
				}
				$order_ji_money -=$this->commission_order['ji_money'];
				$ji_money+=$order_ji_money;
				$remark['order_commission']=array('order_price'=>$order_price,'commission_per'=>$ji_per,'commission_money'=>$order_ji_money);
			}
			$remark['commission_money']=$ji_money;
			if($ji_money>0){
				$this->commission_order['ji_money']+=$ji_money;
				$this->commission_order['commission_money']+=$ji_money;
				$new_commission=array(
						'uniacid'=>$_SESSION['uniacid'],
						'mid'=>$member['mid'],
						'level'=>$commission_level,
						'ordersn'=>$this->order['ordersn'],
						'money'=>$ji_money,
						'jifen'=>0,
						'remark'=>ijson_encode($remark),
						'createtime'=>TIMESTAMP,
						'status'=>1,
						'type'=>1,
				);
				$this->insert('commission',$new_commission);
			}
			//此处判断分红商是否满足升级条件，如果满足则升级分红商等级
			$member_update=array(
				'order_price'=>$member['order_price']+$this->commission_order['order_price'],
				'order_num'=>$member['order_num']+1,
			);
			$this->update('member',$member_update,array('mid'=>$member['mid']));
			$this->model('member')->update_agent_level($member['mid']);
		}
		return $member['agent_id'];
	}
	/*
		全网分红
	*/
	function up_redfee($agent){
			if(!$agent['level_id']){
				//获取默认等级分红比例
				$level_commissions=$this->plugin_setting('default_level');
				$level_id=0;
				$commission_per=$level_commissions['red_rate'];
				$jifen_per=$level_commissions['jifen_rate'];
			}else{
                $level=$this->get('level',array('id'=>$agent['level_id'],'uniacid'=>$_SESSION['uniacid']));
				$level['commissions']=json_decode($level['commissions'],true);
				$level_id=$level['id'];
				$commission_per=$level['commissions']['red_rate'];
				$jifen_per=$level['commissions']['jifen_rate'];
			}
			$money=0;
			$jifen=0;
			$order_price=$this->commission_order['order_price'];
			$remark=array(
				'level_id'=>$level_id,
				'order_price'=>$order_price,
				'goods_commission'=>array(),
			);
        $total_lastcostprice=0;
		if($this->order['goods']){
				$this->needorder=false;
				foreach($this->order['goods'] as $goods){
					$total_price=$goods['total_price']?$goods['total_price']:pdo_getcolumn('jy_weishop_order_goods',array('id'=>$goods['id']),'total_price');
					$goods_commission=$this->get('goods',array('goods_id'=>$goods['goodsid']));
					if($goods_commission['ignore'] || !$goods_commission['id']){
						if($goods_commission['ignore']){
							$order_price=$order_price-$total_price;
						}
						//只要有一个商品，没有独立设置分红，就订单计算佣金
						$this->needorder=true;
						continue;
					}
					//如果商品单独设置佣金，将减少本商品的金额
					$order_price=$order_price-$total_price;
					$goods_commission['commissions']=$goods_commission['commissions']?json_decode($goods_commission['commissions'],true):array();
					$costprice=pdo_getcolumn('jy_weishop_goods',array('id'=>$goods['goodsid']),'costprice');
					$total_costprice=$goods['total']*$costprice;
					$total_lastcostprice +=$total_costprice;
					foreach($goods_commission['commissions'] as $gc){
						if($gc['level_id']==0){
							$demogoods_commission_per=$gc['red_rate'];
							$demojifen_per=$gc['jifen_rate'];
						}
						if($gc['level_id']!=$level_id){
							continue;
						}else{
							$goods_commission_per=$gc['red_rate'];
							$goods_jifen_per=$gc['jifen_rate'];
							break;
						}
					}
					$goods_commission_per=$goods_commission_per?:$demogoods_commission_per;
					$goods_jifen_per=$goods_jifen_per?:$demojifen_per;
					if(substr($goods_commission_per,-1)=='%'){
						//利润计算
						if($this->setting['commissionfeetype']==2){
							$total_price -=$total_costprice;
							$total_lastcostprice -=$total_costprice;
						}
						$goods_commission_money=($total_price*substr($goods_commission_per,0,-1))/100;
					}else{
						$goods_commission_money=$goods_commission_per*$goods['total'];
					}
					if(substr($goods_jifen_per,-1)=='%'){
						$goods_jifen=($goods_commission_money*substr($goods_jifen_per,0,-1))/100;
					}else{
						$goods_jifen=$goods_jifen_per;
					}
					$goods_commission_money-=$goods_jifen;
					$money+=$goods_commission_money;
					$jifen+=$goods_jifen;
				}
			}
			if($order_price>0 || $this->needorder){
				if(substr($commission_per,-1)=='%'){
					//利润计算
					if($this->setting['commissionfeetype']==2){
						$order_price -=$total_lastcostprice;
					}
					$order_commission_money=($goods_commission_money*substr($commission_per,0,-1))/100;
				}else{
					$order_commission_money=$commission_per;
				}
				if(substr($jifen_per,-1)=='%'){
					$order_jinfen=($order_commission_money*substr($jifen_per,0,-1))/100;
				}else{
					$order_jinfen=$jifen_per;
				}
				$order_commission_money -=$order_jinfen;
				$money+=$order_commission_money;
				$jifen+=$order_jinfen;
				$remark['order_commission']=array('order_price'=>$order_price,'commission_per'=>$commission_per,'commission_money'=>$order_commission_money);
			}
			$remark['commission_money']=$money;
			if($money>0 || $jifen>0){
				$this->commission_order['commission_money']+=$money;
				$jifen=$jifen>0?$jifen:0;
				$money=$money>0?$money:0;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$agent['mid'],
					'ordersn'=>$this->order['ordersn'],
					'money'=>$money,
					'jifen'=>$jifen?:0,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>1,
					'type'=>2,
				);
				$this->insert('commission',$new_commission);
			}
			//返回上级
			return $agent['agent_id'];
	}
	/*
		订单完成时，把佣金状态由初始的订单待完成升级为待结算
	*/
	public function order_complete($order){
		$this->update('commission',array('status'=>1,'complete_time'=>TIMESTAMP),array('ordersn'=>$order['ordersn'],'status'=>0));
		$order['api_data']=$order['api_data']?json_decode($order['api_data'],true):array();
		$list=$this->getall('commission',array('ordersn'=>$order['ordersn']));
		foreach($list as $info){
			if($info['jifen']>0){
				if($order['api_data']['merch_dai']==1 && $order['merchid']){
					$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['merchid']));
					if($merch['mid']){
						$member=model('core/member')->detail($merch['mid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
						if($member['credit1']<$info['jifen']){
							continue;
						}
						$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$info['mid']),array('username','nickname'));
						$nickname=$member['nickname']?:$member['username'];
						model('core/member')->member_credit($merch['mid'],'credit1',$info['jifen'],false,'jy_merch','商户扣积分（送['.$nickname.']分红积分）');
					}else{
						continue;
					}
				}
				model('core/member')->add_credit1($info['mid'],$info['jifen'],'佣金兑积分','jy_quanfee');
			}
		}
	}
	/*
		创建结算单
	*/
	public function create_balance($mid,$post=array()){
		if(!$mid){
			exi('请先选择要结算的会员！','error');
		}
		if($post['pay_type']=='downline'){
			if(!$post['wechat']){
				exi('请先填写微信号！','error');
			}
			if(!$post['mobile']){
				exi('请先填写联系电话！','error');
			}
		}
		if($post['pay_type']=='alipay'){
			if(!$post['realname']){
				exi('请先填写真实姓名！','error');
			}
			if(!$post['alipay']){
				exi('请先填写支付宝帐号！','error');
			}
			if(!$post['alipay1']){
				exi('请确认帐号','error');
			}
			if($post['alipay1']!=$post['alipay']){
				exi('确认帐号与支付宝帐号不匹配！','error');
			}
			$typetitle='支付宝';
		}
		if($post['pay_type']=='union'){
			if(!$post['realname']){
				exi('请输入姓名','error');
			}
			if(!$post['bankname']){
				exi('请输入所属银行','error');
			}
			if(!$post['bankcard']){
				exi('请银行卡号','error');
			}
			if(!$post['bankcard1']){
				exi('请确认卡号','error');
			}
			if($post['bankcard']!=$post['bankcard1']){
				exi('确认卡号与银行卡号不匹配！','error');
			}
			$typetitle='银行卡';
		}
		//获取可结算佣金
		$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid,'status'=>1,'isxuni'=>0);
		if($this->setting['balance_day']){
			//结算天数
			$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
			$params['complete_time <']=$time;
		}
		$money=pdo_getsum('jy_quanfee_commission',$params,'money');
		if($money<=0){
			exi('没有可结算的佣金！','error');
		}
		$commission_num=$this->count('commission',$params,'id');
		//结算最低佣金检测
		if($money<$this->setting['balance_money']){
			exi('可结算佣金太少，无法结算！','error');
		}
		if($this->setting['balance_difee']){
			$lastcredit=pdo_getcolumn('core_members',array('id'=>$mid),'credit1');
			if($lastcredit<$money){
				exi('提现需扣除等量积分，您当前积分不足，仅剩'.$lastcredit.'！','error');
			}else{
				cfc('core')->member_credit($mid,'credit1',$money,false,'jy_quanfee','提现扣除等量积分');
			}
		}
		$new_balance=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$mid,
			'balancesn'=>get_ordersn($this->tablename('commission'),'balancesn','AC'),
			'commission_num'=>$commission_num,
			'money'=>$money,
			'pay_type'=>$post['pay_type'],
			'realname'=>$post['realname'],
			'alipay'=>$post['alipay'],
			'bankname'=>$post['bankname'],
			'bankcard'=>$post['bankcard'],
			'wechat'=>$post['wechat'],
			'mobile'=>$post['mobile'],
			'createtime'=>TIMESTAMP,
			'status'=>0,
		);
		//结算手续费
		if($this->setting['balance_per']){
			$new_balance['balance_pay']=intval($new_balance['money']*$this->setting['balance_per'])/100;
		}else{
			$new_balance['balance_pay']=0;
		}
		$new_balance['final_money']=$new_balance['money']-$new_balance['balance_pay'];
		$this->insert('balance',$new_balance);
		$balance_id=pdo_insertid();
		$update=array(
			'status'=>2,
			'balancesn'=>$new_balance['balancesn'],
		);
		$this->update('commission',$update,$params);
		if($post['pay_type']=='credit'){
			$typetitle='余额';
		}
		if($post['pay_type']=='wechat'){
			$typetitle='微信';
		}
		$this->model('notice')->notice_fenxiao_tixian($mid,$money,$typetitle);
		return $balance_id;
	}
	/*
		审核结算单
	*/
	public function check_balance($balance_id,$status,$remark=''){
		$update=array(
			'status'=>$status,
			'check_time'=>TIMESTAMP,
			'remark'=>$remark,
		);
		$this->update('balance',$update,array('id'=>$balance_id));
		return true;
		/*$update=array(
			'status'=>1,
			'balancesn'=>'',
		);
		$balance=$this->get('balance',array('id'=>$balance_id),array('mid','balancesn'));
		if($balance['balancesn']){
			$this->update('commission',$update,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$balance['mid'],'balancesn'=>$balance['balancesn']));
		}*/
		return true;
	}
	/*
		打款结算单
	*/
	public function pay_balance($balance_id,$pay_type='',$wxgid='',$pay_trade_no=''){
		$balance=$this->get('balance',array('id'=>$balance_id,'uniacid'=>$_SESSION['uniacid']));
		if(!$balance || $balance['status']!=1){
			exi('结算单不存在或者不符合打款条件，打款失败！','error');
		}
		$pay_types=array_keys($this->pay_types);
		if(!$pay_type || !in_array($pay_type,$pay_types)){
			//exi('未设置打款方式或者打款方式不合法，打款失败！','error');
		}
		$func_name='pay_balance_by_'.$pay_type;
		$trade_no=$this->$func_name($balance['mid'],$balance['final_money'],$balance['balancesn'],$wxgid);
		$update=array(
			'status'=>3,
			'pay_trade_no'=>$trade_no=='pay_trade_no'?$pay_trade_no:$trade_no,
			'pay_time'=>TIMESTAMP,
		);
		if($pay_type){
			$update['pay_type']=$pay_type;
		}
		$this->update('balance',$update,array('id'=>$balance['id']));
		$this->model('notice')->notice_fenxiao_dakuan($balance['mid'],$balance['final_money']);
		return true;
	}
	/*
		线下打款
	*/
	protected function pay_balance_by_downline(){
		return 'pay_trade_no';
	}
	/*
		打款到余额
	*/
	protected function pay_balance_by_credit($mid,$money,$balancesn){
		return cfc('core')->member_credit($mid,'credit2',$money,true,'jy_quanfee','分红佣金打款');
	}
	/*
		打款到微信零钱
	*/
	protected function pay_balance_by_wechat($mid,$money,$balancesn,$wxgid=''){
		if($wxgid){
			$wxapp=pdo_get('core_account_wxapp',array('id'=>$wxgid,'uniacid'=>$_SESSION['uniacid']),array('appid','mchid','paykey'));
		}
		$params=array(
			'appid'=>$wxapp['appid']?:'',
			'mch_id'=>$wxapp['mchid']?:'',
			'openid'=>$mid,
			'mch_billno'=>$balancesn,
			'money'=>$money,
			'wxgid'=>$wxgid,
			'remark'=>'代理商佣金发放',
		);
		$res=cfc('wechat_pay')->mch_pay($params);
		if(!$res['payment_no']){
			exi('打款到微信零钱失败！','error');
		}
		return $res['payment_no'];
	}
	/*
		打款到支付宝
	*/
	protected function pay_balance_by_alipay($mid,$money,$balancesn){
		return 'pay_trade_no';
		exi('暂不支持打款到支付宝！','error');
	}
	/*
		打款到银行账户
	*/
	protected function pay_balance_by_union($mid,$money,$balancesn){
		return 'pay_trade_no';
		exi('暂不支持打款到银行账户！','error');
	}

	public function commission_remark($remark){
		if(!$remark){
			return '';
		}
		$remark=json_decode($remark,true);
		$goods_str='';
		if($remark['goods_commission']){
			foreach($remark['goods_commission'] as $goods){
				$goods['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$goods['goods_id']),'title');
				$goods_str.="商品ID【{$goods['goods_id']}】，商品名称【{$goods['title']}】，商品数量【{$goods['total']}】，商品总价【{$goods['total_price']}】，佣金规则【{$goods['commission_per']}】，分红佣金【{$goods['commission_money']}】\n";
			}
		}else{
			$goods_str='未启用';
		}
		$remark['level_title']=pdo_getcolumn('jy_quanfee_level',array('uniacid'=>$_SESSION['uniacid'],'level'=>$remark['commission_level']),'title');
		$remark['level_title']=$remark['level_title']?:'默认等级';
		$remark_str=<<<TPL
分红商等级ID【{$remark['level_id']}】，等级名称【{$remark['level_title']}】，佣金等级【{$remark['commission_level']}】，订单总价【{$remark['order_price']}】
商品独立佣金：
{$goods_str}
订单佣金：
除去设置独立佣金的商品外订单金额【{$remark['order_commission']['order_price']}】，佣金规则【{$remark['order_commission']['commission_per']}%】，分红佣金【{$remark['order_commission']['commission_money']}】
佣金总计：【{$remark['commission_money']}】
TPL;
		return $remark_str;
	}
	/*
		获取单独商品佣金
	*/
	protected function get_goodsfee($goodsid,$orderid,$ordergoodsid=''){
		$ordersn=pdo_getcolumn('jy_weishop_order',array('id'=>$orderid,'uniacid'=>$_SESSION['uniacid']),'ordersn');
		$commissionremark=$this->pdo_getcolumn('commission',array('ordersn'=>$ordersn,'uniacid'=>$_SESSION['uniacid']),'remark');
		//print_r($ordersn.'~~'.$commissionremark);exit;
		$commissionremark=json_decode($commissionremark,true);
		
		$goodsfee=0;
		if($commissionremark['goods_commission']){
			foreach($commissionremark['goods_commission'] as $gv){
				if($ordergoodsid){
					if($ordergoodsid==$gv['ordergoodsid']){
						$goodsfee +=$gv['commission_money'];
					}
				}else{
					if($goodsid==$gv['goods_id']){
						$goodsfee +=$gv['commission_money'];
					}
				}
			}
		}
		if($commissionremark['order_commission'] && $goodsfee==0){
			$allorderfee=pdo_getsum('jy_weishop_order_goods',array('orderid'=>$orderid,'goodsid'=>$goodsid),'total_price');
			//exi($allorderfee.'~'.$commissionremark['order_commission']['order_price'].'~'.$commissionremark['order_commission']['commission_money'],'error');
			$goodsfee=($allorderfee/$commissionremark['order_commission']['order_price'])*$commissionremark['order_commission']['commission_money'];
		}
		return $goodsfee;
	}
}